package fun.coding.baozi.practice;

import java.util.Arrays;



public class StephyTestClass {

    // Stephy's code. 
    public int calWaysForCoins (int m) {
        int coins[] = {1, 5, 10, 25};
        Arrays.sort(coins);
        int num = nwaysHelper(0, m, coins);
        return num;
    }
    
    public int nwaysHelper(int n, int m, int[] coins) {
        if (m == 0) {
            return 0;
        }
        if (m < 0) {
            //throw new InvalidInputException();
            return -11111;
        }
        for (int i = 0; i < coins.length; i++) {
            int coin = coins[i];
            if (coin <= m) {
                int temp = nwaysHelper(n, m - coin, coins);

            }
            n = n + 1;
        }
        return n;
    }
    
    public int foo() {
        return -1;
    }
    
    public int matchCoins (int m) {
        int[] coins = new int[] {25, 10, 5, 1};
        if (m == 0) {
            return 0;
        }
        if (m < 0) {
            System.out.println("Amount cannot be negative");
            return -1;
        }
        int num = matchCoinsHelper(0, m, coins, 0);
        return num;
    }
    
    public int matchCoinsHelper(int count, int totalAmount, int[] coins, int index) {
        /*
        if (index >= coins.length) {
            return count + 1;
        }
        */
        if (index == coins.length-1) {
            if (totalAmount % coins[index] == 0) {
          //      count = matchCoinsHelper (count, 0, coins, index + 1);
                return count + 1;
            }
        } else {
            for (int i = 0; i <= totalAmount/coins[index]; i++) {
                count = matchCoinsHelper(count, totalAmount-coins[index] * i, coins, index+1);
            }
        }
        return count;
    }
    
}
